const webpack = require("webpack");
var path = require("path");
var proxy = require("http-proxy-middleware");

function resolve(dir) {
  return path.join(__dirname, dir);
}

function addStyleResource(rule) {
  rule
    .use("style-resource")
    .loader("style-resources-loader")
    .options({
      patterns: [path.resolve(__dirname, "./src/assets/css/main.styl")]
    });
}

module.exports = {
  publicPath: "/",
  outputDir: "dist",
  assetsDir: "assets",
  css: {
    loaderOptions: {
      postcss: {
        plugins: []
      }
    }
  },
  filenameHashing: false,
  // lintOnSave: process.env.NODE_ENV !== "production",
  lintOnSave: false, //关闭代码格式检测
  runtimeCompiler: false,
  productionSourceMap: false,
  configureWebpack: {
    // devtool: "source-map",
    //支持jquery
    plugins: [
      new webpack.ProvidePlugin({
        $: "jquery",
        jQuery: "jquery",
        "windows.jQuery": "jquery"
      })
    ]
  },
  chainWebpack: config => {
    const types = ["vue-modules", "vue", "normal-modules", "normal"];
    types.forEach(type =>
      addStyleResource(config.module.rule("stylus").oneOf(type))
    );
    config.resolve.alias
      .set("pages", resolve("src/pages"))
      .set("common", resolve("src/assets"))
      .set("components", resolve("src/components"));
  },
  devServer: {
    open: process.platform === "darwin",
    host: "0.0.0.0",
    port: 2030,
    disableHostCheck: true,
    proxy: {
      "/fwdj": {
        //target: "http://fwdj.hpwjsns.org.cn:8888/fwdj", // 域名
         target: "http://10.2.98.184:8080", // ip + port 测试用
        ws: true,
        changOrigin: true, //开启代理：在本地会创建一个虚拟服务端，然后发送请求的数据，并同时接收请求的数据，这样服务端和服务端进行数据的交互就不会有跨域问题
        pathRewrite: {
          "^/fwdj": ""
        }
      }
    }
  }
};